package com.jiang.server;

import java.util.HashMap;

/**
 * @author Jiang
 * @version 1.0
 * @date 2023/11/29 14:26
 */
public class ManageServerConnectClientThread {
    private static HashMap<String, ServerConnectClientThread> hm = new HashMap<>();

    public static void addServerConnectClientThread(String userId, ServerConnectClientThread serverConnectClientThread) {
        hm.put(userId, serverConnectClientThread);
    }

    // 返回在线用户列表
    public static String getOnlineUser() {
        StringBuffer stringBuffer = new StringBuffer();
        for (String s : hm.keySet()) {
            stringBuffer.append(s).append(" ");
        }
        return new String(stringBuffer);
    }

    // 从集合中移除某个线程对象
    public static void removeServerConnectClientThread(String userId) {
        hm.remove(userId);
    }

    public static ServerConnectClientThread getServerConnectClientThread(String userId){
        return hm.get(userId);
    }

    public static HashMap<String, ServerConnectClientThread> getHm() {
        return hm;
    }
}
